package com.wms.system.service.impl.wcs;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.wms.common.utils.StringUtils;
import com.wms.system.domain.wcs.ProjectInventory;
import com.wms.system.mapper.wcs.ProjectInventoryMapper;
import com.wms.system.service.wcs.IProjectInventoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.time.LocalDateTime;
import java.util.Arrays;
import java.util.Date;
import java.util.List;

@Service
public class ProjectInventoryServiceImpl implements IProjectInventoryService {
    @Autowired
    private ProjectInventoryMapper projectInventoryMapper;

    public List<ProjectInventory> queryList(ProjectInventory projectInventory){
        List<ProjectInventory> dataList = projectInventoryMapper.selectList(new LambdaQueryWrapper<ProjectInventory>()
                .like(StringUtils.isNotBlank(projectInventory.getCustomeName()),ProjectInventory::getCustomeName,projectInventory.getCustomeName())
                .like(StringUtils.isNotBlank(projectInventory.getProjectCode()),ProjectInventory::getProjectCode,projectInventory.getProjectCode())
                .like(StringUtils.isNotBlank(projectInventory.getGoodsCode()),ProjectInventory::getGoodsCode,projectInventory.getGoodsCode())
                .like(StringUtils.isNotBlank(projectInventory.getInventoryType()),ProjectInventory::getInventoryType,projectInventory.getInventoryType())
                .like(StringUtils.isNotBlank(projectInventory.getSpecs()),ProjectInventory::getSpecs,projectInventory.getSpecs())
                .orderByDesc(ProjectInventory::getCreatedTime)
        );
        return dataList;
    }

    @Override
    public void insert(ProjectInventory projectInventory) {
        projectInventory.setId(null);
        projectInventory.setCreatedTime(LocalDateTime.now());
        projectInventory.setUpdateTime(LocalDateTime.now());
        projectInventoryMapper.insert(projectInventory);
    }

    @Override
    public void update(ProjectInventory projectInventory) {
        projectInventory.setUpdateTime(LocalDateTime.now());
        int i = projectInventoryMapper.updateById(projectInventory);
    }

    @Override
    public ProjectInventory detail(ProjectInventory projectInventory){
        return projectInventoryMapper.selectById(projectInventory.getId());
    }

    @Override
    public void delete(String[] ids) {
        projectInventoryMapper.deleteBatchIds(Arrays.asList(ids));
    }

}
